<?php
namespace Home\Controller;
use Think\Controller;
// 本类由系统自动生成，仅供测试用途
class AdminController extends CommonController {

    public function index(){
        
        $this->display();  
    }

    public function show(){
        import('ORG.Util.Page');
        $user=M('admin');
        $count=$user->count();
        $page=new \Org\Util\page($count,5);
        $page->setConfig('theme','%totalRow% %header%  %upPage% %downPage% %nowPage%/%totalPage% 页');
        $this->show=$page->show();
        $this->rows=$user->limit($page->firstRow,$page->listRows)->order('id')->select();
        $this->display();
    }

    public function add(){
        $this->display(); 
    }

    public function insert(){ 

        $user=M('admin');
        $date=$user->create();
        $user->admin_name=I('post.username');
        $user->admin_password=md5(I('post.password'));
        $user->admin_registertime=time();
        $user->admin_lastlogintime=$user->admin_registertime;
        if($user->add()){
            $this->success('添加成功',U('add'),10);
        }
    }

    public function edit(){
        $user=M('admin');
        $id=I('get.id');
        $this->row=$user->find($id);
        $this->display(); 
    }

    public function update(){
        $user=M('admin');
        $user->create();
        $user->admin_password=md5(I('post.password'));
        if($user->save()){
            $this->success('修改成功',U('show'));
        }
    }

    public function delete(){
        $user=M('admin');
        $id=I('get.id');
        if($user->delete($id)){
            $this->success('删除成功',U('show'));
        }
    }

}